package com.jinzo.mporaba;

import android.content.ContentResolver;
import android.database.Cursor;
import android.os.Bundle;
import android.preference.PreferenceActivity;

public class Preferences extends PreferenceActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            addPreferencesFromResource(R.layout.preferences);	
            ListPreferenceMultiSelect widget_vsebina = (ListPreferenceMultiSelect) findPreference("widget_vsebina");
    		ContentResolver cr = getContentResolver();
    		Cursor c = cr.query(QuotaItem.CONTENT_URI, null, null, null, null);
            startManagingCursor(c);
            
            int count = c.getCount();
            if (count == 0) {
            	count = 1;
            }
            CharSequence[] entries = new CharSequence[count];
            CharSequence[] entryValues = new CharSequence[count];
            if (c.moveToFirst()) {
            	for(int i=0; i<count; i++) {
            		entries[i] = c.getString(c.getColumnIndexOrThrow(DBAdapter.KEY_DISPLAYNAME));
            		entryValues[i] = c.getString(c.getColumnIndexOrThrow(DBAdapter.KEY_ROWID));
            		c.moveToNext();
            	}
            } else {
            	entries[0] = "Ni kategorij, prosim osvežite";
            	entryValues[0] = "NO_CAT";
            }
            c.close();
            widget_vsebina.setEntries(entries);
            widget_vsebina.setEntryValues(entryValues);
            widget_vsebina.setDefaultValue("#ALL#");
    }
}
